<template>
  <a-form
    :model="formState"
    ref="formDataRef"
    name="basic"
    :label-col="{ style: 'width:100px' }"
    :wrapper-col="{ style: 'calc(100% - 100px)' }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <a-form-item label="导入类型" name="uploadType" :rules="[{ required: true, message: '请选择附件类型!' }]">
      <a-select v-model:value="formState.uploadType" placeholder="请选择">
        <!-- <a-select-option :value="1" label="导入装箱信息">导入装箱信息</a-select-option> -->
        <a-select-option :value="2" label="导入收件地址与装箱信息">导入收件地址与装箱信息</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="上传文件" name="file" :rules="[{ required: true, message: '请上传文件!' }]">
      <a-upload v-model:fileList="formState.file" :maxCount="1" :customRequest="uploadRequest" name="file" :multiple="false">
        <a-button>上传</a-button>
      </a-upload>
    </a-form-item>
    <a-form-item label="模板下载">
      <a-button type="link" @click="downloadTemplateHandle">下载发票模板</a-button>
    </a-form-item>
    <a-form-item :wrapper-col="{ offset: 8, span: 16 }" class="submit-btn-form-item">
      <a-button :loading="loading" type="primary" html-type="submit">确定</a-button>
      <a-button @click="resetHandle">取消</a-button>
    </a-form-item>
  </a-form>
</template>

<script lang="ts" setup>
import { toRefs, watch } from "vue";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    passData: ClientWaybillManagement.WaybillDetails;
    type: number; // 1 制作 2修改
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "update:visible", blo: boolean): void;
  (e: "submit", state: Base.GeneraDataType, uploadType: number): void;
}>();
const { visible, passData, type } = toRefs(props);
const { formDataRef, formState, loading } = InitHook();
const { onFinish, onFinishFailed, resetFields, resetHandle, downloadTemplateHandle, uploadRequest } = OperationHook({
  formDataRef,
  formState,
  emit,
  passData,
  loading,
  type
});
watch(
  () => visible.value,
  (v: boolean) => {
    if (!v) {
      resetFields();
      formDataRef.value.clearValidate();
    }
  }
);
</script>
<style lang="stylus" scoped>
:deep(.ant-picker){
    width: 100%;
}
</style>
